import { CommonResult, PageParams, PageResult } from '../types/global'
import { NovelReviewsEntity, ReplyItem, ReviewItem, SearchParam } from '../types/review'
import { http } from '@/utils/http'

/**
 * 新增用户评论表
 * @param data 
 * @returns  
 */
export const addCommentAPI = (data : ReviewItem) => {
	return http<CommonResult>({
		url: '/fanqie/novelReviews/addComment',
		method: 'POST',
		data
	})
}
/**
 * 校验是否已经评论过
 * 
 */
export const checkCommentedAPI = (data : { bookId : number }) => {
	return http<CommonResult>({
		url: '/fanqie/novelReviews/checkCommented',
		method: 'GET',
		data
	})
}


/**
 *  分页查询书评列表
 * @param bookId 图书id
 * @param pageParams 分页参数
 * @returns 书评列表
 */
export const pageReviewsAPI = (
	param : SearchParam,
	pageParams : PageParams,
) => {
	return http<PageResult<ReviewItem[]>>({
		url: '/fanqie/novelReviews/pageReviews',
		method: 'GET',
		data: {
			current: pageParams.current,
			size: pageParams.size
		}
	})

};
/**
 *  分页查询书评列表
 * @param bookId 图书id
 * @param pageParams 分页参数
 * @returns 书评列表
 */
export const pageRepliesAPI = (
	param : SearchParam,
	pageParams : PageParams,) => {
	return http<PageResult<ReviewItem[]>>({
		url: '/fanqie/commentReplies/pageReplies',
		method: 'GET',
		data: {
			current: pageParams.current,
			size: pageParams.size,
			reviewId: param.reviewId,
			parentId: param.parentId
		}
	})

};

/**
 * 新增书评评论
 * @param data 书评评论数据
 * @returns 响应数据
 */
export const postCommentAPI = (data : ReplyItem) => {
	return http<CommonResult>({
		url: '/fanqie/commentReplies/postComment',
		method: 'POST',
		data
	})
}


/**
 * 点赞书评
 * @param data 评论
 * @returns 响应数据
 */
export const likeReplyAPI = (data : ReplyItem) => {
	return http<CommonResult>({
		url: '/fanqie/commentReplies/likeReply',
		method: 'POST',
		data
	})
}

/**
 * 取消点赞
 * @param  data 评论
 * @returns 响应数据
 */
export const unLikeReplyAPI = (data : ReplyItem) => {
	return http<CommonResult>({
		url: '/fanqie/commentReplies/unLikeReply',
		method: 'POST',
		data
	})
}



/**
 * 点赞书评
 * @param data 评论
 * @returns 响应数据
 */
export const likeReviewAPI = (data : NovelReviewsEntity) => {
	return http<CommonResult>({
		url: '/fanqie/novelReviews/likeReview',
		method: 'POST',
		data
	})
}


/**
 * 取消点赞
 * @param  data 评论
 * @returns 响应数据
 */
export const unLikeReviewAPI = (data : NovelReviewsEntity) => {
	return http<CommonResult>({
		url: '/fanqie/novelReviews/unLikeReview',
		method: 'POST',
		data
	})
}